class Solution {
public:
    string longestCommonPrefix(vector<string> &strs) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        if (strs.size() == 0) {
            return string("");
        } else if (strs.size() == 1) {
            return strs[0];
        }

        int len = 0;
        while (true) {
            if (len >= strs[0].length()) {
                break;
            }
            int i = 1;
            char ch = strs[0][len];

            for (; i < strs.size(); ++i) {
                if (len >= strs[i].length() || strs[i][len] != ch) {
                    break;
                }
            }
            if (i < strs.size()) {
                break;
            }
            ++len;
        }
        return strs[0].substr(0, len);
    }
};
